package rth.entities;

import java.io.Serializable;
import java.util.Collections;
import java.util.Map;
import java.util.WeakHashMap;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.proxy.HibernateProxy;

import com.felees.hbnpojogen.persistence.IPojoGenEntity;

/**
 * Object mapping for hibernate-handled table: user.
 * 
 * @author autogenerated
 */

@Entity
@Table(name = "user", catalog = "rth")
public class User implements Cloneable, Serializable, IPojoGenEntity,
		rth.entities.iface.IUser {

	/** Serial Version UID. */
	private static final long serialVersionUID = -559033176L;

	/**
	 * Use a WeakHashMap so entries will be garbage collected once all entities
	 * referring to a saved hash are garbage collected themselves.
	 */
	private static final Map<Serializable, Long> SAVED_HASHES = Collections
			.synchronizedMap(new WeakHashMap<Serializable, Long>());

	/** hashCode temporary storage. */
	private volatile Long hashCode;

	/** Field mapping. */
	private Long defaultProject;
	/** Field mapping. */
	private String deleted;
	/** Field mapping. */
	private String email;
	/** Field mapping. */
	private String emailOnAssignedTo;
	/** Field mapping. */
	private String emailOnBugnote;
	/** Field mapping. */
	private String emailOnClosed;
	/** Field mapping. */
	private String emailOnFeedback;
	/** Field mapping. */
	private String emailOnNew;
	/** Field mapping. */
	private String emailOnPriority;
	/** Field mapping. */
	private String emailOnReopened;
	/** Field mapping. */
	private String emailOnResolved;
	/** Field mapping. */
	private String emailOnStatus;
	/** Field mapping. */
	private String firstName;
	/** Field mapping. */
	private Long id = 0L; // init for hibernate bug workaround
	/** Field mapping. */
	private String lastName;
	/** Field mapping. */
	private String menuPrefs;
	/** Field mapping. */
	private String password;
	/** Field mapping. */
	private String phone;
	/** Field mapping. */
	private String username;
	/** Field mapping. */
	private String userAdmin;

	/**
	 * Default constructor, mainly for hibernate use.
	 */
	public User() {
		// Default constructor
	}

	/**
	 * Constructor taking a given ID.
	 * 
	 * @param id
	 *            to set
	 */
	public User(Long id) {
		this.id = id;
	}

	/**
	 * Constructor taking a given ID.
	 * 
	 * @param defaultProject
	 *            Long object;
	 * @param deleted
	 *            String object;
	 * @param email
	 *            String object;
	 * @param emailOnAssignedTo
	 *            String object;
	 * @param emailOnBugnote
	 *            String object;
	 * @param emailOnClosed
	 *            String object;
	 * @param emailOnFeedback
	 *            String object;
	 * @param emailOnNew
	 *            String object;
	 * @param emailOnPriority
	 *            String object;
	 * @param emailOnReopened
	 *            String object;
	 * @param emailOnResolved
	 *            String object;
	 * @param emailOnStatus
	 *            String object;
	 * @param firstName
	 *            String object;
	 * @param id
	 *            Long object;
	 * @param lastName
	 *            String object;
	 * @param menuPrefs
	 *            String object;
	 * @param password
	 *            String object;
	 * @param phone
	 *            String object;
	 * @param userAdmin
	 *            String object;
	 */
	public User(Long defaultProject, String deleted, String email,
			String emailOnAssignedTo, String emailOnBugnote,
			String emailOnClosed, String emailOnFeedback, String emailOnNew,
			String emailOnPriority, String emailOnReopened,
			String emailOnResolved, String emailOnStatus, String firstName,
			Long id, String lastName, String menuPrefs, String password,
			String phone, String userAdmin) {

		this.defaultProject = defaultProject;
		this.deleted = deleted;
		this.email = email;
		this.emailOnAssignedTo = emailOnAssignedTo;
		this.emailOnBugnote = emailOnBugnote;
		this.emailOnClosed = emailOnClosed;
		this.emailOnFeedback = emailOnFeedback;
		this.emailOnNew = emailOnNew;
		this.emailOnPriority = emailOnPriority;
		this.emailOnReopened = emailOnReopened;
		this.emailOnResolved = emailOnResolved;
		this.emailOnStatus = emailOnStatus;
		this.firstName = firstName;
		this.id = id;
		this.lastName = lastName;
		this.menuPrefs = menuPrefs;
		this.password = password;
		this.phone = phone;
		this.userAdmin = userAdmin;
	}

	/**
	 * Return the type of this class. Useful for when dealing with proxies.
	 * 
	 * @return Defining class.
	 */
	@Transient
	public Class<?> getClassType() {
		return User.class;
	}

	/**
	 * Return the value associated with the column: defaultProject.
	 * 
	 * @return A Long object (this.defaultProject)
	 */
	@Basic(optional = false)
	@Column(name = "default_project", nullable = false)
	public Long getDefaultProject() {
		return this.defaultProject;

	}

	/**
	 * Set the value related to the column: defaultProject.
	 * 
	 * @param defaultProject
	 *            the defaultProject value you wish to set
	 */
	public void setDefaultProject(final Long defaultProject) {
		this.defaultProject = defaultProject;
	}

	/**
	 * Return the value associated with the column: deleted.
	 * 
	 * @return A String object (this.deleted)
	 */
	@Basic(optional = false)
	@Column(nullable = false, length = 1)
	public String getDeleted() {
		return this.deleted;

	}

	/**
	 * Set the value related to the column: deleted.
	 * 
	 * @param deleted
	 *            the deleted value you wish to set
	 */
	public void setDeleted(final String deleted) {
		this.deleted = deleted;
	}

	/**
	 * Return the value associated with the column: email.
	 * 
	 * @return A String object (this.email)
	 */
	@Basic(optional = false)
	@Column(nullable = false, length = 50)
	public String getEmail() {
		return this.email;

	}

	/**
	 * Set the value related to the column: email.
	 * 
	 * @param email
	 *            the email value you wish to set
	 */
	public void setEmail(final String email) {
		this.email = email;
	}

	/**
	 * Return the value associated with the column: emailOnAssignedTo.
	 * 
	 * @return A String object (this.emailOnAssignedTo)
	 */
	@Basic(optional = false)
	@Column(name = "email_on_assigned_to", nullable = false, length = 1)
	public String getEmailOnAssignedTo() {
		return this.emailOnAssignedTo;

	}

	/**
	 * Set the value related to the column: emailOnAssignedTo.
	 * 
	 * @param emailOnAssignedTo
	 *            the emailOnAssignedTo value you wish to set
	 */
	public void setEmailOnAssignedTo(final String emailOnAssignedTo) {
		this.emailOnAssignedTo = emailOnAssignedTo;
	}

	/**
	 * Return the value associated with the column: emailOnBugnote.
	 * 
	 * @return A String object (this.emailOnBugnote)
	 */
	@Basic(optional = false)
	@Column(name = "email_on_bugnote", nullable = false, length = 1)
	public String getEmailOnBugnote() {
		return this.emailOnBugnote;

	}

	/**
	 * Set the value related to the column: emailOnBugnote.
	 * 
	 * @param emailOnBugnote
	 *            the emailOnBugnote value you wish to set
	 */
	public void setEmailOnBugnote(final String emailOnBugnote) {
		this.emailOnBugnote = emailOnBugnote;
	}

	/**
	 * Return the value associated with the column: emailOnClosed.
	 * 
	 * @return A String object (this.emailOnClosed)
	 */
	@Basic(optional = false)
	@Column(name = "email_on_closed", nullable = false, length = 1)
	public String getEmailOnClosed() {
		return this.emailOnClosed;

	}

	/**
	 * Set the value related to the column: emailOnClosed.
	 * 
	 * @param emailOnClosed
	 *            the emailOnClosed value you wish to set
	 */
	public void setEmailOnClosed(final String emailOnClosed) {
		this.emailOnClosed = emailOnClosed;
	}

	/**
	 * Return the value associated with the column: emailOnFeedback.
	 * 
	 * @return A String object (this.emailOnFeedback)
	 */
	@Basic(optional = false)
	@Column(name = "email_on_feedback", nullable = false, length = 1)
	public String getEmailOnFeedback() {
		return this.emailOnFeedback;

	}

	/**
	 * Set the value related to the column: emailOnFeedback.
	 * 
	 * @param emailOnFeedback
	 *            the emailOnFeedback value you wish to set
	 */
	public void setEmailOnFeedback(final String emailOnFeedback) {
		this.emailOnFeedback = emailOnFeedback;
	}

	/**
	 * Return the value associated with the column: emailOnNew.
	 * 
	 * @return A String object (this.emailOnNew)
	 */
	@Basic(optional = false)
	@Column(name = "email_on_new", nullable = false, length = 1)
	public String getEmailOnNew() {
		return this.emailOnNew;

	}

	/**
	 * Set the value related to the column: emailOnNew.
	 * 
	 * @param emailOnNew
	 *            the emailOnNew value you wish to set
	 */
	public void setEmailOnNew(final String emailOnNew) {
		this.emailOnNew = emailOnNew;
	}

	/**
	 * Return the value associated with the column: emailOnPriority.
	 * 
	 * @return A String object (this.emailOnPriority)
	 */
	@Basic(optional = false)
	@Column(name = "email_on_priority", nullable = false, length = 1)
	public String getEmailOnPriority() {
		return this.emailOnPriority;

	}

	/**
	 * Set the value related to the column: emailOnPriority.
	 * 
	 * @param emailOnPriority
	 *            the emailOnPriority value you wish to set
	 */
	public void setEmailOnPriority(final String emailOnPriority) {
		this.emailOnPriority = emailOnPriority;
	}

	/**
	 * Return the value associated with the column: emailOnReopened.
	 * 
	 * @return A String object (this.emailOnReopened)
	 */
	@Basic(optional = false)
	@Column(name = "email_on_reopened", nullable = false, length = 1)
	public String getEmailOnReopened() {
		return this.emailOnReopened;

	}

	/**
	 * Set the value related to the column: emailOnReopened.
	 * 
	 * @param emailOnReopened
	 *            the emailOnReopened value you wish to set
	 */
	public void setEmailOnReopened(final String emailOnReopened) {
		this.emailOnReopened = emailOnReopened;
	}

	/**
	 * Return the value associated with the column: emailOnResolved.
	 * 
	 * @return A String object (this.emailOnResolved)
	 */
	@Basic(optional = false)
	@Column(name = "email_on_resolved", nullable = false, length = 1)
	public String getEmailOnResolved() {
		return this.emailOnResolved;

	}

	/**
	 * Set the value related to the column: emailOnResolved.
	 * 
	 * @param emailOnResolved
	 *            the emailOnResolved value you wish to set
	 */
	public void setEmailOnResolved(final String emailOnResolved) {
		this.emailOnResolved = emailOnResolved;
	}

	/**
	 * Return the value associated with the column: emailOnStatus.
	 * 
	 * @return A String object (this.emailOnStatus)
	 */
	@Basic(optional = false)
	@Column(name = "email_on_status", nullable = false, length = 1)
	public String getEmailOnStatus() {
		return this.emailOnStatus;

	}

	/**
	 * Set the value related to the column: emailOnStatus.
	 * 
	 * @param emailOnStatus
	 *            the emailOnStatus value you wish to set
	 */
	public void setEmailOnStatus(final String emailOnStatus) {
		this.emailOnStatus = emailOnStatus;
	}

	/**
	 * Return the value associated with the column: firstName.
	 * 
	 * @return A String object (this.firstName)
	 */
	@Basic(optional = false)
	@Column(name = "first_name", nullable = false, length = 20)
	public String getFirstName() {
		return this.firstName;

	}

	/**
	 * Set the value related to the column: firstName.
	 * 
	 * @param firstName
	 *            the firstName value you wish to set
	 */
	public void setFirstName(final String firstName) {
		this.firstName = firstName;
	}

	/**
	 * Return the value associated with the column: id.
	 * 
	 * @return A Long object (this.id)
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Basic(optional = false)
	@Column(name = "user_id", nullable = false)
	public Long getId() {
		return this.id;

	}

	/**
	 * Set the value related to the column: id.
	 * 
	 * @param id
	 *            the id value you wish to set
	 */
	public void setId(final Long id) {
		// If we've just been persisted and hashCode has been
		// returned then make sure other entities with this
		// ID return the already returned hash code
		if ((this.id == null || this.id == 0L) && (id != null)
				&& (this.hashCode != null)) {
			SAVED_HASHES.put(id, this.hashCode);
		}
		this.id = id;
	}

	/**
	 * Return the value associated with the column: lastName.
	 * 
	 * @return A String object (this.lastName)
	 */
	@Basic(optional = false)
	@Column(name = "last_name", nullable = false, length = 20)
	public String getLastName() {
		return this.lastName;

	}

	/**
	 * Set the value related to the column: lastName.
	 * 
	 * @param lastName
	 *            the lastName value you wish to set
	 */
	public void setLastName(final String lastName) {
		this.lastName = lastName;
	}

	/**
	 * Return the value associated with the column: menuPrefs.
	 * 
	 * @return A String object (this.menuPrefs)
	 */
	@Basic(optional = false)
	@Column(name = "menu_prefs", nullable = false, length = 39)
	public String getMenuPrefs() {
		return this.menuPrefs;

	}

	/**
	 * Set the value related to the column: menuPrefs.
	 * 
	 * @param menuPrefs
	 *            the menuPrefs value you wish to set
	 */
	public void setMenuPrefs(final String menuPrefs) {
		this.menuPrefs = menuPrefs;
	}

	/**
	 * Return the value associated with the column: password.
	 * 
	 * @return A String object (this.password)
	 */
	@Basic(optional = false)
	@Column(nullable = false, length = 32)
	public String getPassword() {
		return this.password;

	}

	/**
	 * Set the value related to the column: password.
	 * 
	 * @param password
	 *            the password value you wish to set
	 */
	public void setPassword(final String password) {
		this.password = password;
	}

	/**
	 * Return the value associated with the column: phone.
	 * 
	 * @return A String object (this.phone)
	 */
	@Basic(optional = false)
	@Column(nullable = false, length = 25)
	public String getPhone() {
		return this.phone;

	}

	/**
	 * Set the value related to the column: phone.
	 * 
	 * @param phone
	 *            the phone value you wish to set
	 */
	public void setPhone(final String phone) {
		this.phone = phone;
	}

	/**
	 * Return the value associated with the column: username.
	 * 
	 * @return A String object (this.username)
	 */
	@Basic(optional = true)
	@Column(length = 20)
	public String getUsername() {
		return this.username;

	}

	/**
	 * Set the value related to the column: username.
	 * 
	 * @param username
	 *            the username value you wish to set
	 */
	public void setUsername(final String username) {
		this.username = username;
	}

	/**
	 * Return the value associated with the column: userAdmin.
	 * 
	 * @return A String object (this.userAdmin)
	 */
	@Basic(optional = false)
	@Column(name = "user_admin", nullable = false, length = 25)
	public String getUserAdmin() {
		return this.userAdmin;

	}

	/**
	 * Set the value related to the column: userAdmin.
	 * 
	 * @param userAdmin
	 *            the userAdmin value you wish to set
	 */
	public void setUserAdmin(final String userAdmin) {
		this.userAdmin = userAdmin;
	}

	/**
	 * Deep copy.
	 * 
	 * @return cloned object
	 * @throws CloneNotSupportedException
	 *             on error
	 */
	@Override
	public User clone() throws CloneNotSupportedException {

		final User copy = (User) super.clone();

		copy.setDefaultProject(this.getDefaultProject());
		copy.setDeleted(this.getDeleted());
		copy.setEmail(this.getEmail());
		copy.setEmailOnAssignedTo(this.getEmailOnAssignedTo());
		copy.setEmailOnBugnote(this.getEmailOnBugnote());
		copy.setEmailOnClosed(this.getEmailOnClosed());
		copy.setEmailOnFeedback(this.getEmailOnFeedback());
		copy.setEmailOnNew(this.getEmailOnNew());
		copy.setEmailOnPriority(this.getEmailOnPriority());
		copy.setEmailOnReopened(this.getEmailOnReopened());
		copy.setEmailOnResolved(this.getEmailOnResolved());
		copy.setEmailOnStatus(this.getEmailOnStatus());
		copy.setFirstName(this.getFirstName());
		copy.setId(this.getId());
		copy.setLastName(this.getLastName());
		copy.setMenuPrefs(this.getMenuPrefs());
		copy.setPassword(this.getPassword());
		copy.setPhone(this.getPhone());
		copy.setUsername(this.getUsername());
		copy.setUserAdmin(this.getUserAdmin());
		return copy;
	}

	/**
	 * Provides toString implementation.
	 * 
	 * @see java.lang.Object#toString()
	 * @return String representation of this class.
	 */
	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();

		sb.append("defaultProject: " + this.getDefaultProject() + ", ");
		sb.append("deleted: " + this.getDeleted() + ", ");
		sb.append("email: " + this.getEmail() + ", ");
		sb.append("emailOnAssignedTo: " + this.getEmailOnAssignedTo() + ", ");
		sb.append("emailOnBugnote: " + this.getEmailOnBugnote() + ", ");
		sb.append("emailOnClosed: " + this.getEmailOnClosed() + ", ");
		sb.append("emailOnFeedback: " + this.getEmailOnFeedback() + ", ");
		sb.append("emailOnNew: " + this.getEmailOnNew() + ", ");
		sb.append("emailOnPriority: " + this.getEmailOnPriority() + ", ");
		sb.append("emailOnReopened: " + this.getEmailOnReopened() + ", ");
		sb.append("emailOnResolved: " + this.getEmailOnResolved() + ", ");
		sb.append("emailOnStatus: " + this.getEmailOnStatus() + ", ");
		sb.append("firstName: " + this.getFirstName() + ", ");
		sb.append("id: " + this.getId() + ", ");
		sb.append("lastName: " + this.getLastName() + ", ");
		sb.append("menuPrefs: " + this.getMenuPrefs() + ", ");
		sb.append("password: " + this.getPassword() + ", ");
		sb.append("phone: " + this.getPhone() + ", ");
		sb.append("username: " + this.getUsername() + ", ");
		sb.append("userAdmin: " + this.getUserAdmin());
		return sb.toString();
	}

	/**
	 * Equals implementation.
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 * @param aThat
	 *            Object to compare with
	 * @return true/false
	 */
	@Override
	public boolean equals(final Object aThat) {
		Object proxyThat = aThat;

		if (this == aThat) {
			return true;
		}

		if (aThat instanceof HibernateProxy) {
			// narrow down the proxy to the class we are dealing with.
			try {
				proxyThat = ((HibernateProxy) aThat)
						.getHibernateLazyInitializer().getImplementation();
			} catch (org.hibernate.ObjectNotFoundException e) {
				return false;
			}
		}
		if (aThat == null) {
			return false;
		}

		final User that;
		try {
			that = (User) proxyThat;
			if (!(that.getClassType().equals(this.getClassType()))) {
				return false;
			}
		} catch (org.hibernate.ObjectNotFoundException e) {
			return false;
		} catch (ClassCastException e) {
			return false;
		}

		boolean result = true;
		result = result
				&& (((this.getId() == null) && (that.getId() == null)) || (this
						.getId() != null && this.getId().equals(that.getId())));
		result = result
				&& (((getDefaultProject() == null) && (that.getDefaultProject() == null)) || (getDefaultProject() != null && getDefaultProject()
						.equals(that.getDefaultProject())));
		result = result
				&& (((getDeleted() == null) && (that.getDeleted() == null)) || (getDeleted() != null && getDeleted()
						.equals(that.getDeleted())));
		result = result
				&& (((getEmail() == null) && (that.getEmail() == null)) || (getEmail() != null && getEmail()
						.equals(that.getEmail())));
		result = result
				&& (((getEmailOnAssignedTo() == null) && (that
						.getEmailOnAssignedTo() == null)) || (getEmailOnAssignedTo() != null && getEmailOnAssignedTo()
						.equals(that.getEmailOnAssignedTo())));
		result = result
				&& (((getEmailOnBugnote() == null) && (that.getEmailOnBugnote() == null)) || (getEmailOnBugnote() != null && getEmailOnBugnote()
						.equals(that.getEmailOnBugnote())));
		result = result
				&& (((getEmailOnClosed() == null) && (that.getEmailOnClosed() == null)) || (getEmailOnClosed() != null && getEmailOnClosed()
						.equals(that.getEmailOnClosed())));
		result = result
				&& (((getEmailOnFeedback() == null) && (that
						.getEmailOnFeedback() == null)) || (getEmailOnFeedback() != null && getEmailOnFeedback()
						.equals(that.getEmailOnFeedback())));
		result = result
				&& (((getEmailOnNew() == null) && (that.getEmailOnNew() == null)) || (getEmailOnNew() != null && getEmailOnNew()
						.equals(that.getEmailOnNew())));
		result = result
				&& (((getEmailOnPriority() == null) && (that
						.getEmailOnPriority() == null)) || (getEmailOnPriority() != null && getEmailOnPriority()
						.equals(that.getEmailOnPriority())));
		result = result
				&& (((getEmailOnReopened() == null) && (that
						.getEmailOnReopened() == null)) || (getEmailOnReopened() != null && getEmailOnReopened()
						.equals(that.getEmailOnReopened())));
		result = result
				&& (((getEmailOnResolved() == null) && (that
						.getEmailOnResolved() == null)) || (getEmailOnResolved() != null && getEmailOnResolved()
						.equals(that.getEmailOnResolved())));
		result = result
				&& (((getEmailOnStatus() == null) && (that.getEmailOnStatus() == null)) || (getEmailOnStatus() != null && getEmailOnStatus()
						.equals(that.getEmailOnStatus())));
		result = result
				&& (((getFirstName() == null) && (that.getFirstName() == null)) || (getFirstName() != null && getFirstName()
						.equals(that.getFirstName())));
		result = result
				&& (((getLastName() == null) && (that.getLastName() == null)) || (getLastName() != null && getLastName()
						.equals(that.getLastName())));
		result = result
				&& (((getMenuPrefs() == null) && (that.getMenuPrefs() == null)) || (getMenuPrefs() != null && getMenuPrefs()
						.equals(that.getMenuPrefs())));
		result = result
				&& (((getPassword() == null) && (that.getPassword() == null)) || (getPassword() != null && getPassword()
						.equals(that.getPassword())));
		result = result
				&& (((getPhone() == null) && (that.getPhone() == null)) || (getPhone() != null && getPhone()
						.equals(that.getPhone())));
		result = result
				&& (((getUsername() == null) && (that.getUsername() == null)) || (getUsername() != null && getUsername()
						.equals(that.getUsername())));
		result = result
				&& (((getUserAdmin() == null) && (that.getUserAdmin() == null)) || (getUserAdmin() != null && getUserAdmin()
						.equals(that.getUserAdmin())));
		return result;
	}

	/**
	 * Calculate the hashcode.
	 * 
	 * @see java.lang.Object#hashCode()
	 * @return a calculated number
	 */
	@Override
	public int hashCode() {
		if (this.hashCode == null) {
			synchronized (this) {
				if (this.hashCode == null) {
					Long newHashCode = null;

					if (getId() != null) {
						newHashCode = SAVED_HASHES.get(getId());
					}

					if (newHashCode == null) {
						if (getId() != null && getId() != 0L) {
							newHashCode = getId();
						} else {
							newHashCode = (long) super.hashCode();

						}
					}

					this.hashCode = newHashCode;
				}
			}
		}
		return (int) (this.hashCode & 0xffffff);
	}

}
